package cn.com.pureAppApi.exception;

import cn.com.pureAppApi.config.Contract;
import lombok.Data;

/**
 * 统一异常处理
 * @author 
 *

 *
 * QQ讨论群:76989293
 * @email 2696701142@qq.com
 * @date 2018-06-12 16:51:48
 */
@Data
public class ResponseException extends RuntimeException {
	private static final long serialVersionUID = 1L;
    private int code;
    private String msg;
    private ResponseCodeEnum codeEnum;
//    private SystemUpdate update;
//    
//    public ResponseException(SystemUpdate update){
//    	this.code=9999;
//    	this.update=update;
//    	this.msg="";
//    }

    /**
     * Constructs a new runtime exception with {@code null} as its
     * detail message.  The cause is not initialized, and may subsequently be
     * initialized by a call to {@link #initCause}.
     */
    public ResponseException(String msg) {
        this.code =Contract.DEFAULT_FALSE;
        this.msg = msg;
    }

    public ResponseException(ResponseCodeEnum codeEnum) {
        this.codeEnum = codeEnum;
        this.code = codeEnum.getCode();
        this.msg = codeEnum.getMessage();
    }

    public ResponseException(int code,String msg) {
        this.code = code;
        this.msg = msg;
    }   
    
    @Override
    public String getLocalizedMessage() {
        return msg;
    }

    @Override
    public String getMessage() {
        return msg;
    }

}
